package com.example.featuresdk.view

import android.content.res.Configuration
import android.util.Log

/**
 * Utility object for screen dimension,
 */
open class ScreenConstraints {

    //use private setter method to disallow changes
    var screenWithDp :Int = 0
        private set

    var screenHeightDp :Int = 0
        private set

    var appBodyHeightDp: Int = 0
        private set

    var headerWidthDp: Int = 0
        private set

    val appHeaderBarHeightDp :Int  = 40
    val appBottomBarHeightDp :Int  = 50
    val appBottomSpacerHeightDp :Int  = 2
    val headerIconSizeDp :Int = 34

    var softKeyboardHeightDp: Int = 280
        private set

    private lateinit var configuration: Configuration

    fun init(configuration: Configuration){
        this.configuration = configuration
        recalculate()
    }

    companion object{
        const val appHeaderBarHeightDp :Int  = 40
        const val appBottomBarHeightDp :Int  = 50
        const val appBottomSpacerHeightDp :Int  = 2
        const val headerIconSizeDp :Int = 34
    }

    private fun recalculate() {

        this.screenWithDp = configuration.screenWidthDp

        when(android.os.Build.MODEL){
            "Mi 10 Pro" -> {
                this.screenHeightDp = configuration.screenHeightDp + 16
                this.softKeyboardHeightDp = 330
            }
            else -> {
                this.screenHeightDp = configuration.screenHeightDp
                this.softKeyboardHeightDp = 280
            }
        }

        this.appBodyHeightDp = screenHeightDp - appHeaderBarHeightDp - appBottomBarHeightDp - appBottomSpacerHeightDp
        this.headerWidthDp = screenWithDp - headerIconSizeDp * 2
    }
}

